package com.ffs.game.scene;

import com.ffs.persist.utils.TimeUtil;

/**
 * 场景心跳
 *
 * @author ffs80
 */
public class SceneHeartEvent implements Runnable {

    /**
     * 场景
     */
    private GameScene screen;

    /**
     * 最近一次心跳时间
     */
    private long lastHeartTime;

    public SceneHeartEvent(GameScene screen) {
        this.screen = screen;
        this.lastHeartTime = TimeUtil.getNowMils();
    }

    @Override
    public void run() {
        long curTime = TimeUtil.getNowMils();
        int delta = (int) (curTime - lastHeartTime);
        lastHeartTime = curTime;
        if (screen != null) {
            screen.update(delta);
        }
    }
}
